class CheckWX {
	// 位置权限
	static location(callback) {
		// 需在manifest中勾选位置权限并填写说明
		uni.getSetting({
			success: (res) => {  
				if (!res.authSetting['scope.userLocation']) {
					uni.showModal({
						title: '提示',
						content: '请求获取位置权限',
						success: res => {
							if(res.confirm == false) {
								return false;
							}
							uni.openSetting({
								success: res => {
									//如果再次拒绝则返回页面并提示
									if (!res.authSetting['scope.userLocation']) {
										uni.showToast({
											title: '此功能需获取位置信息，请重新设置',
											duration: 3000,
											icon: 'none'
										})
									} else {
										callback();
									}
								}
							})
						}
					})
				} else {
					callback();
				}
			}
		})
	}
	// 录音权限
	static record(callback) {
		uni.getSetting({
			success: (res) => {  
				if (!res.authSetting['scope.record']) {
					uni.showModal({
						title: '提示',
						content: '请求获取录音权限',
						success: res => {
							if(res.confirm == false) {
								return false;
							}
							uni.openSetting({
								success: res => {
									//如果再次拒绝则返回页面并提示
									if (!res.authSetting['scope.record']) {
										uni.showToast({
											title: '此功能需录音授权，请重新设置',
											duration: 3000,
											icon: 'none'
										})
									} else {
										callback();
									}
								}
							})
						}
					})
				} else {
					callback();
				}
			}
		})
	}
}

export default (permissionID, callback) => {
	if (CheckWX[permissionID]) {
		CheckWX[permissionID](callback)
	}
}